//2009/08/15 04:08:09
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class ParameterSubstitution
{
public:
    string processParams(string code, vector <string> params)
    {
        string s;
        for (int i=0; i<code.size(); i++)
        {
			if(code[i] != '$') s += code[i];
			else if(i<code.size() -1 && code[i+1] == '0') s += code[i];
			else
			{
				int num = 0;
				int j;
				for(j=1; i+j<code.size(); j++)
				{
					if(isdigit(code[i+j]))
					{
						if(num * 10 + code[i+j] - '0' <= params.size())
							num = num * 10 + code[i+j] - '0';
						else break;
					}
					else break;
				}
				if(num > 0 && num <= params.size()) 
				{
					s += params[num - 1];
				}
				else s += code.substr(i, j);
				i += j - 1;
			}
        }
		return s;
    }
};
//Copywrite@Blue_Ant;
